package oneD.test;

import java.util.ArrayList;

import oneD.fem.Constraint;
import oneD.fem.Force;
import oneD.fem.structure.Structure;
import oneD.models.TensegrityStructureViewer;



public class TensegrityStructure1 extends TensegrityStructureViewer {

	public TensegrityStructure1(String filePath) {
		super(filePath);
	}

	@Override
	public void manualHandling() {
		Constraint c1 = new Constraint(false, false, false);
		Constraint c2 = new Constraint(false, false, true);
		struct_.getNode(0).setConstraint(c2);
		struct_.getNode(1).setConstraint(c1);
		struct_.getNode(42).setConstraint(c1);
		struct_.getNode(43).setConstraint(c2);

		Force f = new Force(0, -1e3, 0);
		struct_.getNode(18).setForce(f);
		struct_.getNode(25).setForce(f);

		for (int i = 0; i < struct_.getNumberOfElements(); i++)
			if (elementGroup_.get(i) != 1)
				struct_.getElement(i).setPreStress(1e6);
	}

	public static void setGroupConstraint(Structure struct, Constraint c,
			ArrayList<Integer> elementGroup_) {
		/*
		 * set all the node belongs to all element in elementGroupId with
		 * constraint c
		 */
		for (int i = 0; i < struct.getNumberOfElements(); i++) {
			if (elementGroup_.get(i) == 3)
				struct.getElement(i).getNode(1).setConstraint(c);
		}
	}

	public static void main(String[] args) {
		TensegrityStructure1 model = new TensegrityStructure1(
				"c:/tviewer/x11arch.dat");
		
		model.disableShowElementGroupId();
		model.disableShowElementId();
		model.processUserInput();
		
		// TensegrityStructureViewer model = new TensegrityStructureViewer(
		// "c:/tviewer/x11arch.dat");// "c:/tviewer/x48prism1.dat"
		// fem.structure.Tensegrity struct = model.createStructure();
		//
		// manualHandling(struct, model.getElementGroupId());
		//
		// model.initializeVisualizer(struct);
		// model.disableShowElementId();
		// model.disableShowElementGroupId();

		/*
		 * draw the plain structure
		 */
		// model.visualize();
		// model.enableVisualize();

		/*
		 * solution for linear static deformation (for reference)
		 */
		// struct.solve();
		// model.postVisualize();
		// model.enableVisualize();

		/*
		 * solution for nonlinear static deformation
		 */
		// struct.iterateNewtonRaphson(struct.createZeroU());
		// // struct.printResults();
		// model.postVisualize();
		// model.enableVisualize();

		/*
		 * instability analysis using direct computation
		 */
		// IVector u = struct.createZeroU();
		// double lambda = 0;
		// IVector phi = new ArrayVector(struct.enumerateDOFs());
		// BLAM.fill(phi, 0.01);
		// struct.directLoadControlInstabilityComputation(u, lambda, phi);

		/*
		 * instability analysis using second order theory
		 */
		// struct.solve();
		// IVector u = struct.getU();
		// IVector lambda = null;
		// struct.secondOrderLoadControlInstabilityComputation(2, u, lambda);

	}

}
